import requests

class IhrmEmpApi(object):
    @classmethod
    def add_emp(cls, header, req_data):
        resp = requests.post(url="https://heimahr.itheima.net/api/sys/user",headers=header,
                             json=req_data)
        return resp

    @classmethod
    def search_emp(cls, id, header):
        resp = requests.get(url= "https://heimahr.itheima.net/api/sys/user/" + id,
                            headers=header)
        return resp

    @classmethod
    def modify_emp(cls, id, header, req_data):
        resp = requests.put(url="https://heimahr.itheima.net/api/sys/user/" + id,
                     headers=header, json=req_data)
        return resp

    @classmethod
    def delete_emp(cls, id, header):
        resp = requests.delete(url="https://heimahr.itheima.net/api/sys/user/" + id,
                     headers=header)
        return resp

if __name__ == '__main__':
    header = {"Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjEsImlhdCI6MTczODU3MjkwMiwiZXhwIjoxNzM4NTk0NTAyfQ.2ujfqtWhoyuGJ0h0Hmbn5vQd3sNlXOejBXDMei0MPl8"}
    req_data = {"username":"王琦","mobile":"13133322243","workNumber":"","formOfEmployment":1,"departmentId":3,"timeOfEntry":"2024-12-24","correctionTime":"2024-12-30T16:00:00.000Z","staffPhoto":""}
    resp1 = IhrmEmpApi.add_emp(header, req_data)
    print("增加员工:", resp1.json())

    id = 22
    resp2 = IhrmEmpApi.search_emp(id, header)
    print("查询员工:",resp2.json())

    data = {"username": "王"}
    resp3 = IhrmEmpApi.modify_emp(id, header, data)
    print("修改员工:",resp3.json())

    resp4 = IhrmEmpApi.delete_emp(id, header)
    print("删除员工:",resp4.json())

